package com.facebook.common.executors;

import java.util.concurrent.Callable;
import java.util.concurrent.Delayed;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public final class ScheduledFutureImpl<V> implements RunnableFuture<V>, ScheduledFuture<V> {
    private final FutureTask<V> mListenableFuture;

    public ScheduledFutureImpl(Runnable runnable, V obj) {
        this.mListenableFuture = new FutureTask(runnable, obj);
    }

    public ScheduledFutureImpl(Callable<V> callable) {
        this.mListenableFuture = new FutureTask(callable);
    }

    public final boolean cancel(boolean mayInterruptIfRunning) {
        return this.mListenableFuture.cancel(mayInterruptIfRunning);
    }

    public final V get() throws InterruptedException, ExecutionException {
        return this.mListenableFuture.get();
    }

    public final V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        return this.mListenableFuture.get(timeout, unit);
    }

    public final long getDelay(TimeUnit unit) {
        throw new UnsupportedOperationException();
    }

    public final boolean isCancelled() {
        return this.mListenableFuture.isCancelled();
    }

    public final boolean isDone() {
        return this.mListenableFuture.isDone();
    }

    public final void run() {
        this.mListenableFuture.run();
    }


    @Override
    public int compareTo(Delayed delayed) {
        throw new UnsupportedOperationException();
    }
}

